<template>
  <div>
    <BreakSpace label="估价单信息" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
    <TopFilter :list="topFilterList" :cols="3" :collapse="false" :labelWidth="90" :isSubmitBtn="false"></TopFilter>

    <div :style="{ paddingLeft: '10px', minHeight: '200px', paddingBottom: '30px' }">
      <LazyLoadTab v-model="repairActiveName" :tabMenus="repairMenus" @tab-click="tabClickHandle"></LazyLoadTab>
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <!-- <el-button type="primary" icon="el-icon-printer" @click="printOrderClick">打印工单</el-button>
      <el-button v-if="isShow" type="primary" icon="el-icon-printer" @click="printBalanceClick">打印结算单</el-button> -->
      <el-button @click="closeDialog">取消</el-button>
      <!-- <div v-if="printShow">
        <BasePrint ref="print" :data="printList" template="templatePrintFee" />
      </div> -->
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';
import QRcode from 'qrcode';
import { Tag } from 'element-ui';
import { arrayObjDeWeight } from '@/utils/index';
import { getOuterColorList } from '@/api/repair/repairReception/evaluation/index';
import moment from 'moment';
import { constants } from 'crypto';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { getAllUser } from '@/api/finance/advancesReceived/register';
import { getWxlxSelect } from '@/api/repair/repairReception/customer';
import { queryDetailed } from '@/api/repair/queryStatistics/queryEstimateEntrust/index';
import { getroLabourByestimateNOList, getpartByestimateNOList, getaddItemByestimateNO, getEvaluationList } from '@/api/repair/repairReception/evaluation/index';
import { queryPrintData, getRepairTypes, getAdviceLabour, getAdvicePart, getDealerCompanyByCode, getlistAllData } from '@/api/repair/repairReception/feesSettlement';
import { getPinpSelect, getChexSelect, getCheModelSelect, getChexSelectTable, getCheModelSelectTable } from '@/api/repair/repairReception/customer/brand.js';
export default {
  name: 'labourModelsss',
  components: {},
  mixins: [dictionary],
  props: ['list'],
  data() {
    return {
      topFilterList: this.createTopfilter(),
      repairActiveName: '维修项目',
      repairMenus: this.createRepairMenus()
    };
  },

  mounted() {
    this.serviceConsultant();
    this.getWxtypeSelect();
    this.getColor();
    this.getBand();
    this.getSeries();
    this.getModer();
    this.queryDetail();
  },
  methods: {
    createTopfilter() {
      return [
        {
          type: 'INPUT',
          label: '估价单号',
          fieldName: 'ESTIMATE_NO',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'LICENSE',
          disabled: true
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'VIN',

          disabled: true
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'OWNER_NAME',

          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修人',
          fieldName: 'DELIVERER',

          disabled: true
        },
        {
          type: 'SELECT',
          label: '维修类型',
          fieldName: 'REPAIR_TYPE_CODE',

          disabled: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'SERVICE_ADVISOR',

          disabled: true,
          itemList: []
        },
        {
          type: 'DATE_TIME',
          label: '开单日期',
          fieldName: 'RO_CREATE_DATE',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修人手机',
          fieldName: 'DELIVERER_MOBILE',

          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修人电话',
          fieldName: 'DELIVERER_PHONE',

          disabled: true
        },
        {
          type: 'INPUT',
          label: '发动机号',
          fieldName: 'ENGINE_NO',

          disabled: true
        },
        {
          type: 'SELECT',
          label: '送修人性别',
          fieldName: 'DELIVERER_GENDER',

          disabled: true,
          itemList: this.createDictList('8012')
        },

        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'BRAND',

          disabled: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'SERIES',

          disabled: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'MODEL',

          disabled: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '车辆颜色',
          fieldName: 'COLOR',

          disabled: true,
          itemList: []
        },
        {
          type: 'DATE_TIME',
          label: '预交车时间',
          fieldName: 'END_TIME_SUPPOSED',
          disabled: true
        },
        {
          type: 'DATE_TIME',
          label: '完工时间',
          fieldName: 'ITEM_END_TIME',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '燃油量',
          fieldName: 'OIL_REMAIN',

          disabled: true,
          itemList: this.createDictList('8045')
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'IN_MILEAGE',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '检查结果',
          fieldName: 'RO_TROUBLE_DESC',

          disabled: true
        },
        {
          type: 'DATE',
          label: '生产日期',
          fieldName: 'PRODUCT_DATE',

          disabled: true,
          valueFormat: 'yyyy-MM-dd'
        },

        {
          type: 'SELECT',
          label: '估算处理状态',
          fieldName: 'ESTIMATE_HANDLE_STATUS',

          disabled: true,
          itemList: this.createDictList('8113')
        },
        {
          type: 'INPUT',
          label: '厂牌',
          fieldName: 'BRAND_TYPE',

          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '送修问题',
          fieldName: 'CUSTOMER_DESC',
          placeholder: '请输入...',
          disabled: true,
          selfCols: 3,
          rows: 2,
          style: { height: '50px', overflowY: 'auto' }
        }
      ];
    },

    createRepairMenus() {
      let that = this;
      const ESTIMATE_NO = that.list.ESTIMATE_NO;
      return [
        {
          title: '维修项目',
          path: 'repair/queryStatistics/queryEstimateEntrust/repairTabs/repairPro',
          disabled: false,
          params: {
            dataList: [],
            ESTIMATE_NO
          }
        },
        {
          title: '维修材料',
          path: 'repair/queryStatistics/queryEstimateEntrust/repairTabs/repairStuff',
          disabled: false,
          params: {
            dataList: [],
            ESTIMATE_NO
          }
        },
        {
          title: '附加项目',
          path: 'repair/queryStatistics/queryEstimateEntrust/repairTabs/additionalPro',
          disabled: false,
          params: {
            dataList: [],
            ESTIMATE_NO
          }
        },
        {
          title: '维修工具',
          path: 'repair/queryStatistics/queryEstimateEntrust/repairTabs/reception',
          disabled: false,
          params: {
            dataList: [],
            ESTIMATE_NO
          }
        }
      ];
    },

    // 获取服务顾问
    async serviceConsultant() {
      let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      const consultantRes = await searchRoleByCode(consultant);
      // console.log(consultantRes);
      this.topFilterList.find(x => x.fieldName === 'SERVICE_ADVISOR').itemList = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.serviceAdvisorData = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId }));
    },
    async getBand() {
      let res2 = (await getPinpSelect()).data.map(x => ({ value: x.brandId + '', text: x.brandName }));
      this.topFilterList.find(item => item.fieldName === 'BRAND').itemList = res2;
    },
    async getSeries() {
      let res2 = (await getChexSelectTable()).data.map(x => ({ value: x.seriesId + '', text: x.seriesName }));
      this.topFilterList.find(item => item.fieldName === 'SERIES').itemList = res2;
    },
    async getModer() {
      let res2 = (await getCheModelSelectTable()).data.map(x => ({ value: x.modelId + '', text: x.modelName, model: x.modelCode }));
      this.topFilterList.find(item => item.fieldName === 'MODEL').itemList = res2;
    },
    async getColor() {
      let res = await getOuterColorList();
      let data = arrayObjDeWeight(res.data, 'colorCode');
      console.log(data, '颜色');
      this.topFilterList.find(item => item.fieldName === 'COLOR').itemList = data.map(x => ({ value: x.colorCode + '', text: x.colorName }));
    },
    // 获取维修项目类型
    async getWxtypeSelect() {
      const res = await getWxlxSelect();
      // console.log('维修项目==============维修类型' + res);
      this.topFilterList.find(x => x.fieldName === 'REPAIR_TYPE_CODE').itemList = res.data.map(x => ({
        value: x.REPAIR_TYPE_CODE + '',
        text: x.REPAIR_TYPE_NAME
      }));
    },
    async getInvoiceTypeSelect() {
      // const res = await getInvoiceType();
      const handRes = await getAllUser();
      // this.bottomFilterList.find(x => x.fieldName === 'invoiceTypeCode').itemList = res.data.map(x => ({ value: x.INVOICE_TYPE_CODE, text: x.INVOICE_TYPE_NAME }));
      this.bottomFilterList.find(x => x.fieldName === 'balanceHandler').itemList = handRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    },

    // 查询明细
    async queryDetail() {
      const newStr = [];
      const roNo = this.list.ESTIMATE_NO;
      const res = await queryDetailed({ ESTIMATE_NO: roNo });
      if (res.data) {
        // for (let [key, val] of Object.entries(res.data[0])) {
        //   let param = {
        //     fieldName: this.camelcase(key),
        //     value: val
        //   };
        //   newStr.push(param);
        // }
        // this.syncFormListData(newStr);
        // this.vin = this.topFilterList.find(x => x.fieldName === 'vin').initialValue;
        // this.roNo = this.topFilterList.find(x => x.fieldName === 'roNo').initialValue;
        let resList = res.data[0];
        this.topFilterList.forEach(x => {
          x.initialValue = resList[x.fieldName];
        });
      }
    },
    // 字符串转驼峰
    camelcase(str) {
      let arr = str.split('_');
      let upper = arr.map((val, index) => {
        let lowStr = val.toLowerCase();
        if (index) {
          lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
        }
        return lowStr;
      });
      return upper.join('');
    },

    // 把返回的数据赋值给表单
    // async syncFormListData(dataList) {
    //   const formList = [...this.topFilterList];
    //   const formFieldNames = formList.map(x => x.fieldName);
    //   dataList.forEach(x => {
    //     if (formFieldNames.includes(x.fieldName)) {
    //       let target = formList.find(k => k.fieldName === x.fieldName);
    //       if (!target) return;
    //       target.initialValue = x.value;
    //     }
    //     // if (x.fieldName === 'endTimeSupposed') {
    //     //   // console.log(x, 'xxxxx');
    //     //   this.topFilterList.find(x => x.fieldName === 'endTimeSupposed').initialValue = moment(x.value).format('YYYY-MM-DD HH:mm');
    //     // }
    //   });
    // },

    tabClickHandle(tab) {},

    closeDialog() {
      this.$emit('closeDialog');
    }
  }
};
</script>

<style lang="less" scoped>
.panel-heading {
  color: #34495e;
  background-color: #f5f5f5;
  border-color: #ddd;
  padding: 10px 15px;
  margin-bottom: 10px;
}
.model-footer {
  padding: 15px;
  margin-top: 50px;
  text-align: center;
  height: 40px;
  line-height: 40px;
}
</style>
